package com.sit.estatemanagementserver.enity;

import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONWriter;

public record Response<T>(String state, String error, T data) {
    public static <T> Response<T> success() {
        return new Response<T>("success", "", null);
    }
    public static <T> Response<T> success(T data) {
        return new Response<T>("success", "", data);
    }
    public static <T> Response<T> error(String error) {
        return new Response<T>("error", error, null);
    }
    public String asJsonString() {
        return JSONObject.toJSONString(this, JSONWriter.Feature.WriteNulls);
    }
}
